import {Injectable} from '@angular/core';
import {Subject} from 'rxjs/Subject';
import {} from './user';
import {Cookie} from 'ng2-cookies/ng2-cookies';

@Injectable()
export class AuthService {
  private loginStatusSource = new Subject<boolean>();
  private isLogedIn: Boolean = false;
  private tokenId: string;
  private account: string;

  constructor() {
  }

  sendLoginStatus(status: boolean) {
    this.isLogedIn = status;
    this.loginStatusSource.next(status);
  }

  setTokenId(tokenId: string, account: string) {
    Cookie.set('nav-robot-cookie-tokenid', tokenId);
    Cookie.set('account', account);
    this.tokenId = tokenId;
  }

  getTokenId() {
    this.tokenId = Cookie.get('nav-robot-cookie-tokenid');
    return this.tokenId;
  }

  getAccountName() {
    this.account = Cookie.get('account');
    return this.account;
  }

  clearTokenId() {
    this.tokenId = '';
    Cookie.delete('nav-robot-cookie-tokenid');
    Cookie.delete('account');

  }
}
